<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>修改个人信息</title>
        <!-- ===============================================-->
        <!--    导航栏目-->
        <!-- ===============================================-->
        <script src="js/jquery-3.5.1.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/js/bootstrap.bundle.min.js"></script>
        <script src="/assets/js/myjs/head.js"></script>

        <!-- ===============================================-->
        <!--    导航栏目-->
        <!-- ===============================================-->
        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
        <link
                href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
                rel="stylesheet"
        />

        <!-- Icons. Uncomment required icon fonts -->
        <link rel="stylesheet" href="/assets/vendor/fonts/boxicons.css" />

        <!-- Core CSS -->
        <link rel="stylesheet" href="/assets/vendor/css/core.css" class="template-customizer-core-css" />
        <link rel="stylesheet" href="/assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
        <link rel="stylesheet" href="/assets/css/demo.css" />

        <!-- Vendors CSS -->
        <link rel="stylesheet" href="/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />

        <!-- Page CSS -->

        <!-- Helpers -->
        <script src="/assets/vendor/js/helpers.js"></script>

        <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
        <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
        <script src="/assets/js/config.js"></script>
        <script type="text/javascript">
            var user
            $(document).ready(function () {
                
                //------------------------------- -------------------------------
                $.ajax({
                    url: '/usermange/UserInfoServlet',
                    dataType: 'json',
                    type: 'POST',
                    data: {option: 'getloginUser'},
                    success: function (returnValue) {
                          user=returnValue;
                        $("#user_nickname").val(user.user_nickname);
                        $("#user_password").val(user.user_password);
                        $("#user_email").val(user.user_email);
                        $("#user_phone").val(user.user_phone);
                        if(user.user_sex=="男"){
                            $("#inlineRadio1").prop("checked",true);
                        }else{
                            $("#inlineRadio2").prop("checked",true);
                        }




                    }
                })

            })

            $(function () {
                var flagUsername = false;
                var flagPassword = false;
                var flagConfirmpwd = false;
                var flagEmail = false;
                var flagTelephone = false;

                function checkUsername() {
                    if ($("#user_nickname").val() == "") {
                        $("#usernameMsg").text("用户名不能为null")
                        flagUsername = false;
                        return;
                    }

                    reg = /^\w{2,8}$/;
                    if (reg.test($("#user_nickname").val()) == false) {
                        $("#usernameMsg").text("用户名必须是2-8位");
                        flagUsername = false;
                        return;
                    }

                    var name= $("#user_nickname").val();
                    if(user.user_nickname==name){

                        $("#usernameMsg").text("用户名没有修改");
                        flagUsername = true;
                        return;
                    }
                    $.ajax({
                        url: '/usermange/UserInfoServlet',
                        dataType: 'html',
                        type: 'POST',
                        data: {option: "checkUsername", username: $("#user_nickname").val(), random: Math.random()},
                        success: function (returnvalue) {


                            // alert(returnvalue)
                            if (returnvalue == "true") {

                                $("#usernameMsg").text("此用户名可使用");
                                flagUsername = true;
                            } else if (returnvalue == "false") {

                                $("#usernameMsg").text("此用户名不可使用");
                                flagUsername = false;
                            }
                        }
                    });
                }

                $("#user_nickname").blur(function () {
                    checkUsername();
                });



                function checkPassword() {

                    reg = /^\w{6,12}$/;
                    if (reg.test($("#user_password").val()) == false) {
                        $("#passwordMsg").text("密码必须是6-12位");
                        flagPassword = false;
                    } else {
                        $("#passwordMsg").text("密码格式正确");
                        flagPassword = true;
                    }
                }
                $("#user_password").blur(function () {

                    checkPassword();
                });


                function checkConfirmpwd() {
                    if ($("user_password").val() == "") {
                        $("#confirmpwdMsg").text("密码不能为null")
                        flagConfirmpwd = false;
                        return;
                    }
                    var pwd = $("#user_password").val();
                    var repwd = $("#confirmpwd").val();

                    if (pwd == repwd) {
                        $("#confirmpwdMsg").text("密码验证正确");
                        flagConfirmpwd = true;
                    } else {
                        $("#confirmpwdMsg").text("密码验证失败");
                        flagConfirmpwd = false;
                    }
                }
                $("#confirmpwd").blur(function () {
                    checkConfirmpwd();
                });


                function checkEmail() {
                    var reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                    var email = $("#user_email").val();
                    if (reg.test(email)) {
                        $("#emailMsg").text("邮件格式正确");

                    } else {
                        $("#emailMsg").text("邮件格式错误");
                        flagEmail = false;
                        return ;
                    }
                    var emailss= $("#user_email").val();
                    if(user.user_email==emailss){
                        alert(emailss)
                        $("#emailMsg").text("邮箱没有修改");
                        flagEmail = true;
                        return;
                    }
                    $.ajax({
                        url: '/usermange/UserInfoServlet',
                        dataType: 'html',
                        type: 'POST',
                        data: {option: "checkEmail", Email: $("#user_email").val(), random: Math.random()},
                        success: function (returnvalue) {

                            if (returnvalue == "true") {

                                $("#emailMsg").text("邮箱可以注册");
                                flagEmail = true;

                            } else if (returnvalue == "false") {

                                $("#emailMsg").text("邮箱不可以注册");
                                flagEmail = false;

                            }
                        }
                    });
                }
                $("#user_email").blur(function () {
                    checkEmail();
                });


                function checkTele() {
                    var reg = /^1[3|4|5|7|8][0-9]{9}$/;
                    var tele = $("#user_phone").val();
                    if (reg.test(tele)) {

                    } else {
                        $("#telephoneMsg").text("手机号码格式错误");
                        flagTelephone = false;
                        return;
                    }
                    var teleff= $("#user_phone").val();
                    if(user.user_phone==teleff){

                        $("#telephoneMsg").text("手机没有修改");
                        flagTelephone   = true;
                        return;
                    }
                    $.ajax({
                        url: '/usermange/UserInfoServlet',
                        dataType: 'html',
                        type: 'POST',
                        data: {option: "checkTele", Tele: $("#user_phone").val(), random: Math.random()},
                        success: function (returnvalue) {

                            if (returnvalue == "true") {

                                $("#telephoneMsg").text("手机可以注册");
                                flagTelephone = true;

                            } else if (returnvalue == "false") {

                                $("#telephoneMsg").text("手机不可以注册");
                                flagTelephone = false;

                            }
                        }
                    });

                }

                $("#user_phone").blur(function () {
                    checkTele();
                });


                $("#submitButton").click(function () {


                    if (flagUsername && flagPassword && flagConfirmpwd && flagEmail && flagTelephone) {
                        $.ajax({
                            url: '/usermange/UserInfoServlet',
                            dataType: 'html',
                            type: 'POST',
                            data: {option: "updateloginUser",
                                user_id:user.user_id,
                                user_nickname: $("#user_nickname").val(),
                                user_phone: $("#user_phone").val(),
                                user_email: $("#user_email").val(),
                                user_password: $("#user_password").val(),

                                random: Math.random()},
                            success: function (returnvalue) {
                                alert("修改成功")
                            }
                        });
                    }
                    else {
                        console.log(flagUsername+' flagUsername');
                        console.log(flagPassword+' flagPassword');
                        console.log(flagConfirmpwd+' flagConfirmpwd');
                        console.log(flagEmail+' flagEmail');
                        console.log(flagTelephone+'  flagTelephone');
                    }
                });
            });
        </script>

    </head>
    <body>
        <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top " id="mynav">
            <div class="container px-4 px-lg-5">
                <a class="navbar-brand" href="#!">XDDRead</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                        data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span></button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0 ms-lg-4" id="navbarUl">

                    </ul>
                    <form class="d-flex">
                        <button class="btn btn-outline-dark" type="submit">
                            <i class="bi-cart-fill me-1"></i>
                            Cart
                            <span class="badge bg-dark text-white ms-1 rounded-pill">0</span>
                        </button>
                    </form>
                </div>
            </div>
        </nav>
        <div class="container">
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8" style="background:#fff;padding:40px 80px;margin:30px;border:7px solid #ccc;">

                    <form class="form-horizontal" style="margin-top:5px;" action="/usermange/UserInfoServlet" name="regForm" method="post"
                          enctype="multipart/form-data" onsubmit="return false">
                        <input type="hidden" name="option" value="updataUser">
                        <!--                用户名-->
                        <div class="form-group">
                            <h2 class="form-group">修改用户</h2>
                            <label for="user_nickname" class="col-sm-2 control-label">用户名</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="user_nickname" name="user_nickname" placeholder="请输入用户名">
                                <span id="usernameMsg"></span>
                            </div>
                        </div>

                        <!--                密码-->
                        <div class="form-group">
                            <label for="user_password" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control" id="user_password" name="user_password" placeholder="请输入密码">
                                <span id="passwordMsg"></span>
                            </div>
                        </div>
                        <!--                确认密码-->
                        <div class="form-group">
                            <label for="confirmpwd" class="col-sm-2 control-label">确认密码</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control" id="confirmpwd" name="confirmpwd"
                                       placeholder="请输入确认密码">
                                <span id="confirmpwdMsg"></span>
                            </div>
                        </div>
                        <!--                邮箱-->
                        <div class="form-group">
                            <label for="user_email" class="col-sm-2 control-label">Email</label>
                            <div class="col-sm-6">
                                <input type="email" class="form-control" id="user_email" name="user_email" placeholder="请输入邮箱">
                                <span id="emailMsg"></span>
                            </div>
                        </div>

                        <div class="form-group opt">
                            <label for="inlineRadio1" class="col-sm-2 control-label">性别</label>
                            <div class="col-sm-6">
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="inlineRadio1" value="男" >男
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="inlineRadio2" value="女">女
                                </label>
                            </div>
                        </div>
                        <!--                电话-->
                        <div class="form-group">
                            <label for="user_phone" class="col-sm-2 control-label">电话</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="user_phone" name="user_phone" placeholder="请输入电话号码">
                                <span id="telephoneMsg"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-2 col-sm-10">
                                <input type="submit" id="submitButton" width="100" value="修改" border="0">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="col-md-2"></div>
        </div>
     <!--   <div class="layout-container">
            <div class="container-fluid">
                <div class="content-wrapper">
                    <div class="container-xxl flex-grow-1 container-p-y  ">
                        <div class="col-md-7" >
                            <div class="card mb-4 ">
                                <div class="card-header d-flex align-items-center justify-content-between">
                                    <h5 class="mb-0">修改用户信息</h5>
                                    <small class="text-muted float-end">个人信息</small>
                                </div>
                                <div class="card-body">
                                    <form>
                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-name">name</label>
                                            <div class="col-sm-10">
                                                <input type="text" class="form-control" id="basic-default-name" placeholder="名称">
                                            </div>
                                        </div>

                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-email">Email</label>
                                            <div class="col-sm-10">
                                                <div class="input-group input-group-merge">
                                                    <input type="text" id="basic-default-email" class="form-control" placeholder="邮箱" aria-label="john.doe" aria-describedby="basic-default-email2">
                                                    <span class="input-group-text" id="basic-default-email2">@qq.com</span>
                                                </div>
                                                <div class="form-text"></div>
                                            </div>
                                        </div>
                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-email">sex</label>

                                            <div class="col-sm-10">
                                                <div class="form-check form-check-inline mt-3">
                                                    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
                                                    <label class="form-check-label" for="inlineRadio1">男</label>
                                                </div>
                                                <div class="form-check form-check-inline">
                                                    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">
                                                    <label class="form-check-label" for="inlineRadio2">女</label>
                                                </div>
                                            </div>


                                        </div>
                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-phone">Phone No</label>
                                            <div class="col-sm-10">
                                                <input type="text" id="basic-default-phone" class="form-control phone-mask" placeholder="电话" aria-label="658 799 8941" aria-describedby="basic-default-phone">
                                            </div>
                                        </div>
                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-message">password</label>
                                            <div class="col-sm-10">
                                                <textarea id="basic-default-message" class="form-control" placeholder="密码" aria-label="密码" aria-describedby="basic-icon-default-message2"></textarea>
                                            </div>
                                        </div>
                                        <div class="row mb-3">
                                            <label class="col-sm-2 col-form-label" for="basic-default-message">角色</label>
                                            <div class="col-sm-10">
                                                <select class="form-select" id="exampleFormControlSelect1" aria-label="Default select example">
                                                    <option selected="">Open this select menu</option>
                                                    <option value="1">One</option>
                                                    <option value="2" aria-checked="true">Two</option>
                                                    <option value="3">Three</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="row justify-content-end">
                                            <div class="col-sm-10">
                                                <button type="submit" class="btn btn-primary">Send</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>


                </div>

            </div>

        </div>-->

    </body>
</html>